package com.hxd.otc.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ArrayRes;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;

import com.hxd.otc.base.BaseApplication;

/**
 * Created by lzy on 2018/5/31 0031.
 * description ${资源工具类}
 */
public class ResourceUtil {

    @ColorInt
    public static int getColor(@ColorRes int id) {
        return ContextCompat.getColor(getContext(), id);
    }

    @NonNull
    public static String getString(@StringRes int resId, Object... formatArgs) {
        return getContext().getString(resId, formatArgs);
    }

    @NonNull
    public static String getString(@StringRes int resId) {
        return getContext().getString(resId);
    }

    public static String[] getStringArray(@ArrayRes int resId) {
        return getContext().getResources().getStringArray(resId);
    }

    @Nullable
    public static Drawable getDrawable(@DrawableRes int id) {
        Drawable drawable = ContextCompat.getDrawable(getContext(), id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        return drawable;
    }

    private static Context getContext() {
        return BaseApplication.getInstance();
    }
}
